package com.lfy.common.result;

import com.lfy.common.enums.BaseEnum;
import lombok.Data;

@Data
public class R<T> {
    private String msg;
    private Integer code;
    private T data;
    public R(){

    }

    public R(String msg, Integer code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public static <T>R<T> success(String msg,T data){
        return new R<T>(msg,200,data);
    }
    public static <T>R<T> success(T data){
        return success("success",data);
    }
    public static <T>R<T> success(BaseEnum baseEnum){
        return success(baseEnum.getMsg(),null);
    }
    public static <T>R<T> success(BaseEnum e, T data){
        return new R<T>(e.getMsg(),e.getCode(),data);
    }
    public static <T>R<T> success(){
        return new R<T>("success",200,null);
    }

    public static <T>R<T> error(){
        return error("error",500);
    }
    public static <T>R<T> error(String msg){
        return error(msg,500);
    }
    public static <T>R<T> error(String msg,Integer code){
        return new R<T>(msg,code,null);
    }
    public static <T>R<T> error(BaseEnum e){
        return error(e.getMsg(),e.getCode());
    }

    public static void main(String[] args) {
        System.out.println(R.error());
        System.out.println(R.success());
    }
}
